﻿using Grpc.Core;

using static System.ConfigCenter.SystemConfigurations;

namespace System.ConfigCenter.Client
{
    /// <summary>
    /// 配置管理
    /// </summary>
    public class Manager
    {
        /// <summary>
        /// 根据路径获取一个配置信息
        /// </summary>
        /// <param name="path">路径信息</param>
        /// <param name="currentEventID">当前追踪事件ID</param>
        /// <returns></returns>
        /// <exception cref="ApplicationException"></exception>
        public static string GetByPath(string[] path, string currentEventID)
        {
            var metaData = new Metadata();
            if (!string.IsNullOrEmpty(currentEventID))
            {
                metaData.Add("GCCEventID", currentEventID);
            }
            if (ClientInstance.Instance is null)
            {
                throw new ApplicationException("Please init the client first.");
            }
            var request = new GetByPathRequest();
            foreach (var item in path)
            {
                request.Path.Add(item);
            }
            var response = new SystemConfigurationsClient(ClientInstance.Instance).GetByPath(request, metaData);
            return response.Value;
        }
    }
}
